<template>
	

	<view class="content">
		
		
		
		<!-- <uni-card :title="value.targetName" extra="" >
			<uni-forms-item label="当前:" >
				<text class="uni-body" style="line-height: 36px;">{{value.income}}</text>
			</uni-forms-item>
			<uni-forms-item label="新获取金币:" >
				<text class="uni-body" style="line-height: 36px;">{{value.newIncme}}</text>
			</uni-forms-item>
			
		</uni-card> -->
				
					
	
		
	
	</view>
<view>
	    <ad-rewarded-video ref="adRewardedVideo" adpid="1610972564" :preload="false" :loadnext="false" :disabled="true"
	      v-slot:default="{loading, error}" @load="onadload" @close="onadclose" @error="onaderror">
	      <view class="ad-error" v-if="error">{{error}}</view>
	    </ad-rewarded-video>
	    <button type="primary" :disabled="isLoading" :loading="isLoading" @click="showAd">观看广告</button>
		<button type="primary"  @click="addIncome">增加积分</button>
	  </view>

				
</template>

<script>
	import store from '@/store/index.js';//需要引入store
	export default {
			computed:{
				
				
			},
			components: {},
			data() {
				return {
					isLoading: false,
					value:{
						income:10,
						newIncme:10,
						userId:"",
						title:"当前记录"
						
					}
					
				
				
				}
			},
			onLoad(option) {
				//加载新闻通知数据
				this.$data.value.userId=option.userId;
				console.log(option.userId)
				
			},
			onReady() {
			  this.isLoading = true;
			  this.$refs.adRewardedVideo.load();
			},
			methods: {
			  showAd() {
			    if (this.isLoading) {
			      return
			    }
			    this.$refs.adRewardedVideo.show();
			  },
			  onadload(e) {
			    this.isLoading = false;
			    console.log('广告数据加载成功');
			  },
			  onadclose(e) {
				let self=this;
			    const detail = e.detail
			    // 用户点击了【关闭广告】按钮
			    if (detail && detail.isEnded) {
					store.dispatch('addIncomeData',{"userId":self.$data.userId,"income":10}).then(() => {
					
						
						uni.showToast({
						  title: "金币已增加",
						  icon: "none"
						})
					})
			      // 正常播放结束
			      console.log("onClose " + detail.isEnded);
			    } else {
			      // 播放中途退出
			      console.log("onClose " + detail.isEnded);
			    }
			    //this.isLoading = true;
			    //this.$refs.adRewardedVideo.load();
			  },
			  onaderror(e) {
			    // 广告加载失败
			    console.log(e.detail);
			    this.isLoading = false;
			  },
			  addIncome(){
				  store.dispatch('addIncomeData',{"userId":this.$data.userId,"income":10}).then(() => {
				  
				  	
				  	uni.showToast({
				  	  title: "金币已增加",
				  	  icon: "none"
				  	})
				  })
			  }
			}
		}
</script>

<style>
.container {
		overflow: hidden;
	}

	.custom-cover {
		flex: 1;
		flex-direction: row;
		position: relative;
	}

	.cover-content {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		height: 40px;
		background-color: rgba($color: #000000, $alpha: 0.4);
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 15px;
		font-size: 14px;
		color: #fff;
	}

	.card-actions {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		height: 45px;
		border-top: 1px #eee solid;
	}

	.card-actions-item {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.card-actions-item-text {
		font-size: 12px;
		color: #666;
		margin-left: 5px;
	}

	.cover-image {
		flex: 1;
		height: 150px;
	}

	.no-border {
		border-width: 0;
	}
</style>